package com.c0der.neat;

import java.io.Serializable;
import java.util.Objects;

public class Connection implements Serializable {
    private final int innovation;
    private int from, to;
    private double weight = 0, bias = 0;
    private boolean enable;

    public Connection(int from, int to, double weight, double bias, boolean enable) {
        this.innovation = Innovation.newInnovation();
        this.from = from;
        this.to = to;
        this.weight = weight;
        this.bias = bias;
        this.enable = enable;
    }

    public Connection(Connection connection) {
        this.innovation = connection.innovation;
        this.from = connection.from;
        this.to = connection.to;
        this.weight = connection.weight;
        this.bias = connection.bias;
        this.enable = connection.enable;
    }

    public int getInnovation() {
        return innovation;
    }

    public int getFrom() {
        return from;
    }

    public void setFrom(int from) {
        this.from = from;
    }

    public int getTo() {
        return to;
    }

    public void setTo(int to) {
        this.to = to;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public double getBias() {
        return bias;
    }

    public void setBias(double bias) {
        this.bias = bias;
    }

    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Connection that = (Connection) o;
        return from == that.from &&
                to == that.to;
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to);
    }
}
